package org.jetnuke.dao.sqlserver;

import org.apache.log4j.Logger;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.List;

import net.jforum.JForumExecutionContext;
import net.jforum.util.preferences.SystemGlobals;

public class SqlServerReviewsDAO extends
		org.jetnuke.dao.generic.GenericReviewsDAO {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger
			.getLogger(SqlServerReviewsDAO.class);

	public List selectOrderDateDesc(int limit) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectOrderDateDesc(int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p;

		String q1 = SystemGlobals.getSql("GenericModel.selectByLimit");
		String q2 = SystemGlobals.getSql("ReviewModel.selectOrderDateDesc");
		p = JForumExecutionContext.getConnection().prepareStatement(
				q1 + " " + limit + " " + q2);

		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectOrderDateDesc(int) - end"); //$NON-NLS-1$
		}
		return list;
	}

	public List selectOrderHitsDesc(int limit) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectOrderHitsDesc(int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p;

		String q1 = SystemGlobals.getSql("GenericModel.selectByLimit");
		String q2 = SystemGlobals.getSql("ReviewModel.selectOrderHitsDesc");
		p = JForumExecutionContext.getConnection().prepareStatement(
				q1 + " " + limit + " " + q2);

		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectOrderHitsDesc(int) - end"); //$NON-NLS-1$
		}
		return list;
	}

	public List selectOrderIDDesc(int limit) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug("selectOrderIDDesc(int) - start"); //$NON-NLS-1$
		}

		PreparedStatement p;

		String q1 = SystemGlobals.getSql("GenericModel.selectByLimit");
		String q2 = SystemGlobals.getSql("ReviewModel.selectOrderIDDesc");
		p = JForumExecutionContext.getConnection().prepareStatement(
				q1 + " " + limit + " " + q2);

		ResultSet rs = p.executeQuery();
		List list = this.processSelectAll(rs);
		rs.close();
		p.close();

		if (logger.isDebugEnabled()) {
			logger.debug("selectOrderIDDesc(int) - end"); //$NON-NLS-1$
		}
		return list;
	}
}
